/**
 * Created with JetBrains PhpStorm.
 * User: Bezdelnick
 * Date: 29.03.13
 * Time: 15:32
 * To change this template use File | Settings | File Templates.
 */

function applyJquery() {
    $('.jquery-button').button().css('font-size', '0.85em');

    $(".jquery-multi-select").multiselect({
        size:20//,
        //css_class_selected:"test-selection",
        //header: "Выберите" //, autoOpen: true
    });
}

function updateContentContainer(container, data) {
    //alert('updateContentContainer || ' + container.attr('action'));
    $.ajax({
        type:'POST',
        url:container.attr('action'),
        data:data,
        success:function (response) {
            container.html(response);
            applyJquery();
            createLinks();
        },
        error:function (response) {
            console.log(response);
        }
    });
}


$(function () {

    $('#admin-navig-tabs').tabs();
    $('.jquery-button').button().css('font-size', '0.75em');

    $('.ajax-content-container').each(function (index) {
        updateContentContainer($(this), '');
    });

    $('.refresh-content-container-link').click(function (index) {
        var container = $('#' + $(this).attr('contentContainerId'));
        updateContentContainer(container, '');
    });

    $('.search-button').click(function (index) {
        var container = $('#' + $(this).attr('contentContainerId'));
        updateContentContainer(container, getSerialisedForm('#search_films_form', 'show'));
    });

    $('').button({
        click : function () {
            $.ajax({
                type:'POST',
                url:$('#edit_film_form').attr('action'),
                data:getSerialisedForm('#edit_film_form', 'edit'),
                success:function (response) {
                    updateContentContainer(filmContentContainer, '');
                }
            });
        }
    });
});